
yanhx.addCommon("load",function(){
	yanhx.exec("tableHandle.init");
});
(function(){
	var head={
	name:{"name":"工程名称","css":{"width":"15%"}},
	comname:{"name":"公司简称","css":{"width":"15%"}},
	state:{"name":"状态","css":{"width":"10%"}},
	open_state:{"name":"开标状态","css":{"width":"10%"}},
	opendate:{"name":"开标时间","css":{"width":"10%"}},
	bill_state:{"name":"保证金","css":{"width":"10%"}},
	biaoshu_state:{"name":"标书状态","css":{"width":"10%"}},
	kaiBiao:{"name":"项目经理","css":{"width":"10%"}},
	pername:{"name":"操作人","css":{"width":"10%"}}
};
var template="<div class='table_template'><div class='tr'>" +
"<div class='td' jtext='name'></div>" +
"<div class='td' jtext='comname'></div>" +
"<div class='td' jtext='state'></div>" +
"<div class='td' jtext='open_state'></div>" +
"<div class='td' jtext='opendate'></div>" +
"<div class='td' jtext='bill_state'></div>" +
"<div class='td' jtext='biaoshu_state'></div>" +
"<div class='td' jtext='kaiBiao'></div>" +
"<div class='td' jtext='pername'></div>" +
"</div></div>";
	yanhx.addComponent("tableHandle",{
		head:head,
		temp:$(template),
		tableDiv:null,
		table:null,
		headElem:null,
	    pageSize:20,
		init:function(){
			this.tableDiv=$("#table");
			this.table=this.tableDiv.children("#tableBody");
			this.headElem=this.tableDiv.children("#tableHead");
			this.table.listTable({
				head:this.headElem,
				//头配置
				curCfg:this.head,
				//模板
				curTemp:this.temp
			});	
		},
		query:function(param){
			this.param=param;
			param.callback=this.doBack;
			param.param.pageSize=this.pageSize;
			$.java(param);
		},
		doBack:function(data){
			yanhx.exec("tableHandle.fillTable",data);
		},
		fillTable:function(data){
			this.table.listTable({
				clean:true,
				data:data
			});
		}
	});
})();


yanhx.addCommon("load",function(){
	yanhx.exec("qryHandle.init");
	yanhx.exec("qryHandle.qryCond",[
 {id:"name",name:"工程名称",type:"input"},
 {id:"com_id",key:"com_id",name:"公司",type:"select"},
 {id:"bill_state",key:"billState",name:"保证金",type:"select"},
 {id:"biaoshu_state",key:"biaoshuState",name:"标书","type":"select"}
]);
});
yanhx.addComponent("qryHandle",{
	cond:null,
	curQry:null,
	//创建查询条件
	dateRange:function(src){
		this.curQry=src;
		$(common.DateRange).tagWin(this.setDate);
	},
	normal:function(src){
		this.curQry=src;
		$("<input />").tagWin(this.setInput);
	},
	levelReq:function(src){
		this.curQry=src;
		$(common.levelReq).openWin({src:src,callback:this.setLevel});
	},
	setLevel:function(){
		var handle=yanhx.find("qryHandle");
		var obj=this.content.getBean();
		obj=obj[handle.curQry.attr("name")];
		var desc=yanhx.exec("mutilHandle.getDesc");
		if(obj&&obj.length){
			handle.setCond({
				src:handle.curQry,
				val:{
					id:obj,
					name:desc
				}
			});
		}
	},
	setInput:function(){
		var val=this.content.find("input").val().trim();
		var handle=yanhx.find("qryHandle");
		if(val!=""){
			handle.setCond({
				src:handle.curQry,
				val:{
					id:val,
					name:val
				}
			});
		}
	},
	setDate:function(){
		var handle=yanhx.find("qryHandle");
		var obj=this.content.getBean();
		if(obj.beginDate||obj.endDate){
			handle.setCond({
				src:handle.curQry,
				val:{
					id:obj,
					name:obj.beginDate+"~"+obj.endDate
				}
			});
		}
	},
	qryCond:function(data){
		var len=data.length;
		for(var i=0;i<len;i++){
			var li=$("<li cb='qryHandle.setCond' class='query_li' name="+data[i].id+" key="+data[i].key+">"+data[i].name+"</li>").appendTo(this.qryItem);
			if(data[i].type=="area"){
				li.attr("callFunc","click:qryHandle.pickArea");
			}else if(data[i].type=="select"){
				li.attr("callFunc","click:mutilHandle.select");
			}else if(data[i].type=="dateRange"){
				li.attr("callFunc","click:qryHandle.dateRange");
			}else if(data[i].type=="levelReq"){
				li.attr("callFunc","click:qryHandle.levelReq");
			}else if(data[i].type=="input"){
				li.attr("callFunc","click:qryHandle.normal");
			}
			else{
				li.attr("callFunc","click:field_def").attr("title",data[i].name)
				.attr("model","single").attr("action","common");
			}
		}
	},
	setArea:function(data){
		var param={
			src:this
		};
		if(data.county){
			param.val=data.county;
		}
		else if(data.city){
			param.val=data.city;
		}
		else if(data.province){
			param.val=data.province;
		}
		else{
			//没有选择 则不处理
			return;
		}
		param.val.name=param.val.text;
		yanhx.exec("qryHandle.setCond",param)
	},
	pickArea:function(src){
		var elem=$(common.area_single);
		elem.open({
			model:true,
			src:src,
			title:'区域选择',
			callback:this.setArea
		});
		yanhx.exec("areaHandle.query",{
			func:$.java,
			data:{
				action:'common.qryArea',
				param:{parent:0}
			},
			elem:elem
		});
	},
	del:function(src){
		src.parent().remove();
		this.doQry();
	},
	setCond:function(param){
		this.curQry=null;
		var key=param.src.attr("name");
		var val=param.val;
		var item=this.qryTag.find("#"+key);
		if(!item.length){
			item=$('<div class="qryTab submitField" id='+key+' name='+key+'><div class="qryTabContent"></div><div class="ctrl" callFunc="click:qryHandle.del"></div></div>').appendTo(this.qryTag);
		}
		else{
			var old=item.data("jsonValue");
			//没有变化则不处理
			if(old==val.id)
				return;
		}
		//判断是否叠加查询
		if(!this.isAdd.attr("checked")){
			this.qryTag.empty();
			this.qryTag.append(item);
		}
		item.data("jsonValue",val.id);
		var text=param.src.text()+":"+val.name;
		item.find(".qryTabContent").text(text).attr("title",text);
		this.doQry();
	},
	doQry:function(){
		//判断是否即时查询
		if(this.isQuery.attr("checked")){
			this.qry();
		}
	},
	qry:function(){
		this.cond=this.qryTag.getBean();
		this.cond.page=1;
		yanhx.exec("tableHandle.query",{
			action:'company.qryDustry',
			param:this.cond
		});
	},
	reset:function(){
		this.qryTag.empty();
		this.qry();
	},
	init:function(){
		this.qryContent=$("#quikQryContent");
		this.qryTag=this.qryContent.children(".qry_tag");
		this.qryItem=$("#quikQryCond");
		this.isAdd=this.qryContent.find("input.isAddCond");
		this.isQuery=this.qryContent.find("input.isCurQuery");
		yanhx.exec("tableHandle.query",{
			action:'company.qryDustry',
			param:{page:1}
		});
	}
});


var common;
var jxd_data;
function setCommon(data){
	common=data;
};
//获取登录信息
yanhx.addCommon("ready",function(){
	$.java({
		action:'common.getLoginData',
		param:{str_array:['com_id']},
		callback:function(data){
			for(var k in data){
				var val=data[k];
				yanhx.exec("mutilHandle.save",{
					key:k,
					val:val
				});
			}
		}
	});
});
function setData(data){
	jxd_data=data;
	for(var k in data){
		var val=data[k];
		$("#"+k).fillSelect(val);
		yanhx.exec("mutilHandle.save",{
			key:k,
			val:val
		});
	}
}
//获取文本及和数据字典
yanhx.addCommon("load",function(){
	$.java({
		action:'common.text',
		param:{str_array:[]},
		callback:setCommon
	});
	$.java({
		action:'common.data',
		param:{str_array:['billState','biaoshuState']},
		callback:setData
	});
});
